<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="学习笔记,java,mybatis," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="前言这几天自己建了一个测试项目，想用SSM框架来搭建，在使用Mybatis的时候偶尔发现原来Mybatis有代码生成器可以自动生成代码。于是就去了解了一番，在这里做个笔记。">
<meta property="og:type" content="article">
<meta property="og:title" content="使用MyBatis Generator自动创建代码">
<meta property="og:url" content="http://jieminblog.tk/2017/03/09/使用MyBatis-Generator自动创建代码/index.html">
<meta property="og:site_name" content="jiemin's Blog">
<meta property="og:description" content="前言这几天自己建了一个测试项目，想用SSM框架来搭建，在使用Mybatis的时候偶尔发现原来Mybatis有代码生成器可以自动生成代码。于是就去了解了一番，在这里做个笔记。">
<meta property="og:image" content="http://omdsjtsd2.bkt.clouddn.com/17-3-9/99367944-file_1489042640112_ab73.png">
<meta property="og:image" content="http://omdsjtsd2.bkt.clouddn.com/17-3-9/71750463-file_1489043010854_cf6.png">
<meta property="og:updated_time" content="2017-03-09T07:20:30.912Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用MyBatis Generator自动创建代码">
<meta name="twitter:description" content="前言这几天自己建了一个测试项目，想用SSM框架来搭建，在使用Mybatis的时候偶尔发现原来Mybatis有代码生成器可以自动生成代码。于是就去了解了一番，在这里做个笔记。">
<meta name="twitter:image" content="http://omdsjtsd2.bkt.clouddn.com/17-3-9/99367944-file_1489042640112_ab73.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://jieminblog.tk/2017/03/09/使用MyBatis-Generator自动创建代码/"/>





  <title> 使用MyBatis Generator自动创建代码 | jiemin's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  














  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">jiemin's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">本来无一物，何处惹尘埃</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://jieminblog.tk/2017/03/09/使用MyBatis-Generator自动创建代码/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="我爱的乌托邦">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/touxiang.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="jiemin's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                使用MyBatis Generator自动创建代码
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-09T15:12:09+08:00">
                2017-03-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>这几天自己建了一个测试项目，想用SSM框架来搭建，在使用<code>Mybatis</code>的时候偶尔发现原来<code>Mybatis</code>有代码生成器可以自动生成代码。于是就去了解了一番，在这里做个笔记。<br><a id="more"></a></p>
<h1 id="MyBatis-Generator"><a href="#MyBatis-Generator" class="headerlink" title="MyBatis Generator"></a>MyBatis Generator</h1><blockquote>
<p>MyBatis属于一种半自动的ORM框架，所以主要的工作就是配置Mapping映射文件，但是由于手写映射文件很容易出错，所以可利用MyBatis生成器自动生成实体类、DAO接口和Mapping映射文件。</p>
</blockquote>
<p>使用自动生成的方式有很多种，我尝试了其中的两种。</p>
<h2 id="使用maven插件"><a href="#使用maven插件" class="headerlink" title="使用maven插件"></a>使用maven插件</h2><h3 id="配置pom-xml"><a href="#配置pom-xml" class="headerlink" title="配置pom.xml"></a>配置pom.xml</h3><p>给pom.xml加Mybatis的plugin</p>
<figure class="highlight dts"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line"><span class="params">&lt;plugin&gt;</span></div><div class="line">	<span class="params">&lt;groupId&gt;</span>org.mybatis.generator<span class="params">&lt;/groupId&gt;</span></div><div class="line">	<span class="params">&lt;artifactId&gt;</span>mybatis-generator-maven-plugin<span class="params">&lt;/artifactId&gt;</span></div><div class="line">	<span class="params">&lt;version&gt;</span><span class="number">1.3</span><span class="number">.2</span><span class="params">&lt;/version&gt;</span></div><div class="line">	<span class="params">&lt;configuration&gt;</span></div><div class="line">		<span class="params">&lt;configurationFile&gt;</span>src<span class="meta-keyword">/main/</span>resources/generatorConfig.xml<span class="params">&lt;/configurationFile&gt;</span></div><div class="line">		<span class="params">&lt;verbose&gt;</span>true<span class="params">&lt;/verbose&gt;</span></div><div class="line">		<span class="params">&lt;overwrite&gt;</span>true<span class="params">&lt;/overwrite&gt;</span></div><div class="line">	<span class="params">&lt;/configuration&gt;</span></div><div class="line">	</div><div class="line">	<span class="params">&lt;dependencies&gt;</span></div><div class="line">		<span class="params">&lt;dependency&gt;</span></div><div class="line">			<span class="params">&lt;groupId&gt;</span>org.mybatis.generator<span class="params">&lt;/groupId&gt;</span></div><div class="line">			<span class="params">&lt;artifactId&gt;</span>mybatis-generator-core<span class="params">&lt;/artifactId&gt;</span></div><div class="line">			<span class="params">&lt;version&gt;</span><span class="number">1.3</span><span class="number">.2</span><span class="params">&lt;/version&gt;</span></div><div class="line">		<span class="params">&lt;/dependency&gt;</span></div><div class="line">	<span class="params">&lt;/dependencies&gt;</span></div><div class="line"><span class="params">&lt;/plugin&gt;</span></div></pre></td></tr></table></figure>
<h3 id="配置generatorConfig-xml"><a href="#配置generatorConfig-xml" class="headerlink" title="配置generatorConfig.xml"></a>配置generatorConfig.xml</h3><p>在src\main\resources路径下新建generatorConfig.xml ，内容如下:</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line"><span class="php"><span class="meta">&lt;?</span>xml version=<span class="string">"1.0"</span> encoding=<span class="string">"UTF-8"</span><span class="meta">?&gt;</span></span>    </div><div class="line"><span class="meta">&lt;!DOCTYPE generatorConfiguration    </span></div><div class="line">  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"    </div><div class="line">  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"&gt;    </div><div class="line"><span class="tag">&lt;<span class="name">generatorConfiguration</span>&gt;</span>    </div><div class="line"><span class="comment">&lt;!-- 数据库驱动--&gt;</span>    </div><div class="line">    <span class="tag">&lt;<span class="name">classPathEntry</span>  <span class="attr">location</span>=<span class="string">"/Users/zjm/dependencies/mysql/mysql-connector-java/5.1.30/mysql-connector-java-5.1.30.jar"</span>/&gt;</span>    </div><div class="line">    <span class="tag">&lt;<span class="name">context</span> <span class="attr">id</span>=<span class="string">"mysql"</span>  <span class="attr">targetRuntime</span>=<span class="string">"MyBatis3"</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">commentGenerator</span>&gt;</span>    </div><div class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"suppressDate"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span>    </div><div class="line">            <span class="comment">&lt;!-- 是否去除自动生成的注释 true：是 ： false:否 --&gt;</span>    </div><div class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"suppressAllComments"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span>    </div><div class="line">        <span class="tag">&lt;/<span class="name">commentGenerator</span>&gt;</span>    </div><div class="line">        <span class="comment">&lt;!--数据库链接URL，用户名、密码 --&gt;</span>    </div><div class="line">        <span class="tag">&lt;<span class="name">jdbcConnection</span> <span class="attr">driverClass</span>=<span class="string">"com.mysql.jdbc.Driver"</span> <span class="attr">connectionURL</span>=<span class="string">"jdbc:mysql://127.0.0.1:3306/gx"</span> <span class="attr">userId</span>=<span class="string">"root"</span> <span class="attr">password</span>=<span class="string">"Zjm123456!"</span>&gt;</span>    </div><div class="line">        <span class="tag">&lt;/<span class="name">jdbcConnection</span>&gt;</span>    </div><div class="line">        <span class="tag">&lt;<span class="name">javaTypeResolver</span>&gt;</span>    </div><div class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"forceBigDecimals"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span>    </div><div class="line">        <span class="tag">&lt;/<span class="name">javaTypeResolver</span>&gt;</span>    </div><div class="line">        <span class="comment">&lt;!-- 生成模型的包名和位置--&gt;</span>    </div><div class="line">        <span class="tag">&lt;<span class="name">javaModelGenerator</span> <span class="attr">targetPackage</span>=<span class="string">"com.gx.domain"</span> <span class="attr">targetProject</span>=<span class="string">"src/main/java"</span>&gt;</span>    </div><div class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"enableSubPackages"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span>    </div><div class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"trimStrings"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span>    </div><div class="line">        <span class="tag">&lt;/<span class="name">javaModelGenerator</span>&gt;</span>    </div><div class="line">        <span class="comment">&lt;!-- 生成映射文件的包名和位置--&gt;</span>    </div><div class="line">        <span class="tag">&lt;<span class="name">sqlMapGenerator</span> <span class="attr">targetPackage</span>=<span class="string">"Mappings"</span> <span class="attr">targetProject</span>=<span class="string">"src/main/resources"</span>&gt;</span>    </div><div class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"enableSubPackages"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span>    </div><div class="line">        <span class="tag">&lt;/<span class="name">sqlMapGenerator</span>&gt;</span>    </div><div class="line">        <span class="comment">&lt;!-- 生成DAO的包名和位置--&gt;</span>    </div><div class="line">        <span class="tag">&lt;<span class="name">javaClientGenerator</span> <span class="attr">type</span>=<span class="string">"XMLMAPPER"</span> <span class="attr">targetPackage</span>=<span class="string">"com.gx.dao"</span> <span class="attr">targetProject</span>=<span class="string">"src/main/java"</span>&gt;</span>    </div><div class="line">            <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"enableSubPackages"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span>    </div><div class="line">        <span class="tag">&lt;/<span class="name">javaClientGenerator</span>&gt;</span>    </div><div class="line">        <span class="comment">&lt;!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名--&gt;</span>    </div><div class="line">        <span class="tag">&lt;<span class="name">table</span> <span class="attr">tableName</span>=<span class="string">"user_t"</span> <span class="attr">domainObjectName</span>=<span class="string">"User"</span> <span class="attr">enableCountByExample</span>=<span class="string">"false"</span> <span class="attr">enableUpdateByExample</span>=<span class="string">"false"</span> <span class="attr">enableDeleteByExample</span>=<span class="string">"false"</span> <span class="attr">enableSelectByExample</span>=<span class="string">"false"</span> <span class="attr">selectByExampleQueryId</span>=<span class="string">"false"</span>&gt;</span><span class="tag">&lt;/<span class="name">table</span>&gt;</span>  </div><div class="line">    <span class="tag">&lt;/<span class="name">context</span>&gt;</span>    </div><div class="line"><span class="tag">&lt;/<span class="name">generatorConfiguration</span>&gt;</span></div></pre></td></tr></table></figure>
<h3 id="执行maven命令"><a href="#执行maven命令" class="headerlink" title="执行maven命令"></a>执行maven命令</h3><p><code>mvn mybatis-generator:generate</code></p>
<p>生成后如下图：</p>
<p><img src="http://omdsjtsd2.bkt.clouddn.com/17-3-9/99367944-file_1489042640112_ab73.png" alt=""></p>
<p>需要手动改一下Dao接口的名字</p>
<h2 id="使用mybatis-generator的jar包直接生成"><a href="#使用mybatis-generator的jar包直接生成" class="headerlink" title="使用mybatis-generator的jar包直接生成"></a>使用mybatis-generator的jar包直接生成</h2><h3 id="把mybatis-generator-core-1-3-2-jar和generatorConfig-xml放在同一目录下"><a href="#把mybatis-generator-core-1-3-2-jar和generatorConfig-xml放在同一目录下" class="headerlink" title="把mybatis-generator-core-1.3.2.jar和generatorConfig.xml放在同一目录下"></a>把mybatis-generator-core-1.3.2.jar和generatorConfig.xml放在同一目录下</h3><p><img src="http://omdsjtsd2.bkt.clouddn.com/17-3-9/71750463-file_1489043010854_cf6.png" alt=""></p>
<h3 id="执行命令"><a href="#执行命令" class="headerlink" title="执行命令"></a>执行命令</h3><p><code>java -jar mybatis-generator-core-1.3.1.jar -configfile generatorConfig.xml -overwrite</code></p>
<p>使用这种方式需要注意配置文件中的路径，最好使用绝对路径。</p>
<h1 id="参考文件"><a href="#参考文件" class="headerlink" title="参考文件"></a>参考文件</h1><figure class="highlight dust"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div><div class="line">165</div><div class="line">166</div><div class="line">167</div><div class="line">168</div><div class="line">169</div><div class="line">170</div><div class="line">171</div><div class="line">172</div><div class="line">173</div><div class="line">174</div><div class="line">175</div><div class="line">176</div><div class="line">177</div><div class="line">178</div><div class="line">179</div><div class="line">180</div><div class="line">181</div><div class="line">182</div><div class="line">183</div><div class="line">184</div><div class="line">185</div><div class="line">186</div><div class="line">187</div><div class="line">188</div><div class="line">189</div><div class="line">190</div><div class="line">191</div><div class="line">192</div><div class="line">193</div><div class="line">194</div><div class="line">195</div><div class="line">196</div><div class="line">197</div><div class="line">198</div><div class="line">199</div><div class="line">200</div><div class="line">201</div><div class="line">202</div><div class="line">203</div><div class="line">204</div><div class="line">205</div><div class="line">206</div><div class="line">207</div><div class="line">208</div><div class="line">209</div><div class="line">210</div><div class="line">211</div><div class="line">212</div><div class="line">213</div><div class="line">214</div><div class="line">215</div><div class="line">216</div><div class="line">217</div><div class="line">218</div><div class="line">219</div><div class="line">220</div><div class="line">221</div><div class="line">222</div><div class="line">223</div><div class="line">224</div><div class="line">225</div><div class="line">226</div><div class="line">227</div><div class="line">228</div><div class="line">229</div><div class="line">230</div><div class="line">231</div><div class="line">232</div><div class="line">233</div><div class="line">234</div><div class="line">235</div><div class="line">236</div><div class="line">237</div><div class="line">238</div><div class="line">239</div><div class="line">240</div><div class="line">241</div><div class="line">242</div><div class="line">243</div><div class="line">244</div><div class="line">245</div><div class="line">246</div><div class="line">247</div><div class="line">248</div><div class="line">249</div><div class="line">250</div><div class="line">251</div><div class="line">252</div><div class="line">253</div><div class="line">254</div><div class="line">255</div><div class="line">256</div><div class="line">257</div><div class="line">258</div><div class="line">259</div><div class="line">260</div><div class="line">261</div><div class="line">262</div><div class="line">263</div><div class="line">264</div><div class="line">265</div><div class="line">266</div><div class="line">267</div><div class="line">268</div><div class="line">269</div><div class="line">270</div><div class="line">271</div><div class="line">272</div><div class="line">273</div><div class="line">274</div><div class="line">275</div><div class="line">276</div><div class="line">277</div><div class="line">278</div><div class="line">279</div><div class="line">280</div><div class="line">281</div><div class="line">282</div><div class="line">283</div></pre></td><td class="code"><pre><div class="line"><span class="xml"><span class="php"><span class="meta">&lt;?</span>xml version=<span class="string">"1.0"</span> encoding=<span class="string">"UTF-8"</span><span class="meta">?&gt;</span></span></span></div><div class="line"><span class="meta">&lt;!DOCTYPE generatorConfiguration</span></div><div class="line">  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"</div><div class="line">"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"&gt;</div><div class="line"><span class="comment">&lt;!-- 配置生成器 --&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">generatorConfiguration</span>&gt;</span></div><div class="line"><span class="comment">&lt;!-- 可以用于加载配置项或者配置文件，在整个配置文件中就可以使用$</span><span class="template-variable">&#123;propertyKey&#125;</span><span class="xml"><span class="comment">的方式来引用配置项</span></span></div><div class="line">    resource：配置资源加载地址，使用resource，MBG从classpath开始找，比如com/myproject/generatorConfig.properties        </div><div class="line">    url：配置资源加载地质，使用URL的方式，比如file:///C:/myfolder/generatorConfig.properties.</div><div class="line">    注意，两个属性只能选址一个;</div><div class="line"></div><div class="line">    另外，如果使用了mybatis-generator-maven-plugin，那么在pom.xml中定义的properties都可以直接在generatorConfig.xml中使用</div><div class="line">&lt;properties resource="" url="" /&gt;</div><div class="line"> --&gt;</div><div class="line"></div><div class="line"> <span class="comment">&lt;!-- 在MBG工作的时候，需要额外加载的依赖包</span></div><div class="line">     location属性指明加载jar/zip包的全路径</div><div class="line">&lt;classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" /&gt;</div><div class="line">  --&gt;</div><div class="line"></div><div class="line"><span class="comment">&lt;!-- </span></div><div class="line">    context:生成一组对象的环境 </div><div class="line">    id:必选，上下文id，用于在生成错误时提示</div><div class="line">    defaultModelType:指定生成对象的样式</div><div class="line">        1，conditional：类似hierarchical；</div><div class="line">        2，flat：所有内容（主键，blob）等全部生成在一个对象中；</div><div class="line">        3，hierarchical：主键生成一个XXKey对象(key class)，Blob等单独生成一个对象，其他简单属性在一个对象中(record class)</div><div class="line">    targetRuntime:</div><div class="line">        1，MyBatis3：默认的值，生成基于MyBatis3.x以上版本的内容，包括XXXBySample；</div><div class="line">        2，MyBatis3Simple：类似MyBatis3，只是不生成XXXBySample；</div><div class="line">    introspectedColumnImpl：类全限定名，用于扩展MBG</div><div class="line">--&gt;</div><div class="line"><span class="tag">&lt;<span class="name">context</span> <span class="attr">id</span>=<span class="string">"mysql"</span> <span class="attr">defaultModelType</span>=<span class="string">"hierarchical"</span> <span class="attr">targetRuntime</span>=<span class="string">"MyBatis3Simple"</span> &gt;</span></div><div class="line"></div><div class="line">    <span class="comment">&lt;!-- 自动识别数据库关键字，默认false，如果设置为true，根据SqlReservedWords中定义的关键字列表；</span></div><div class="line">        一般保留默认值，遇到数据库关键字（Java关键字），使用columnOverride覆盖</div><div class="line">     --&gt;</div><div class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"autoDelimitKeywords"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line">    <span class="comment">&lt;!-- 生成的Java文件的编码 --&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"javaFileEncoding"</span> <span class="attr">value</span>=<span class="string">"UTF-8"</span>/&gt;</span></div><div class="line">    <span class="comment">&lt;!-- 格式化java代码 --&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"javaFormatter"</span> <span class="attr">value</span>=<span class="string">"org.mybatis.generator.api.dom.DefaultJavaFormatter"</span>/&gt;</span></div><div class="line">    <span class="comment">&lt;!-- 格式化XML代码 --&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"xmlFormatter"</span> <span class="attr">value</span>=<span class="string">"org.mybatis.generator.api.dom.DefaultXmlFormatter"</span>/&gt;</span></div><div class="line"></div><div class="line">    <span class="comment">&lt;!-- beginningDelimiter和endingDelimiter：指明数据库的用于标记数据库对象名的符号，比如ORACLE就是双引号，MYSQL默认是`反引号； --&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"beginningDelimiter"</span> <span class="attr">value</span>=<span class="string">"`"</span>/&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"endingDelimiter"</span> <span class="attr">value</span>=<span class="string">"`"</span>/&gt;</span></div><div class="line"></div><div class="line">    <span class="comment">&lt;!-- 必须要有的，使用这个配置链接数据库</span></div><div class="line">        @<span class="doctag">TODO:</span>是否可以扩展</div><div class="line">     --&gt;</div><div class="line">    <span class="tag">&lt;<span class="name">jdbcConnection</span> <span class="attr">driverClass</span>=<span class="string">"com.mysql.jdbc.Driver"</span> <span class="attr">connectionURL</span>=<span class="string">"jdbc:mysql:///pss"</span> <span class="attr">userId</span>=<span class="string">"root"</span> <span class="attr">password</span>=<span class="string">"admin"</span>&gt;</span></div><div class="line">        <span class="comment">&lt;!-- 这里面可以设置property属性，每一个property属性都设置到配置的Driver上 --&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">jdbcConnection</span>&gt;</span></div><div class="line"></div><div class="line">    <span class="comment">&lt;!-- java类型处理器 </span></div><div class="line">        用于处理DB中的类型到Java中的类型，默认使用JavaTypeResolverDefaultImpl；</div><div class="line">        注意一点，默认会先尝试使用Integer，Long，Short等来对应DECIMAL和 NUMERIC数据类型； </div><div class="line">    --&gt;</div><div class="line">    <span class="tag">&lt;<span class="name">javaTypeResolver</span> <span class="attr">type</span>=<span class="string">"org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl"</span>&gt;</span></div><div class="line">        <span class="comment">&lt;!-- </span></div><div class="line">            true：使用BigDecimal对应DECIMAL和 NUMERIC数据类型</div><div class="line">            false：默认,</div><div class="line">                scale&gt;0;length&gt;18：使用BigDecimal;</div><div class="line">                scale=0;length[10,18]：使用Long；</div><div class="line">                scale=0;length[5,9]：使用Integer；</div><div class="line">                scale=0;length&lt;5：使用Short；</div><div class="line">         --&gt;</div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"forceBigDecimals"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">javaTypeResolver</span>&gt;</span></div><div class="line"></div><div class="line"></div><div class="line">    <span class="comment">&lt;!-- java模型创建器，是必须要的元素</span></div><div class="line">        负责：1，key类（见context的defaultModelType）；2，java类；3，查询类</div><div class="line">        targetPackage：生成的类要放的包，真实的包受enableSubPackages属性控制；</div><div class="line">        targetProject：目标项目，指定一个存在的目录下，生成的内容会放到指定目录中，如果目录不存在，MBG不会自动建目录</div><div class="line">     --&gt;</div><div class="line">    <span class="tag">&lt;<span class="name">javaModelGenerator</span> <span class="attr">targetPackage</span>=<span class="string">"com._520it.mybatis.domain"</span> <span class="attr">targetProject</span>=<span class="string">"src/main/java"</span>&gt;</span></div><div class="line">        <span class="comment">&lt;!--  for MyBatis3/MyBatis3Simple</span></div><div class="line">            自动为每一个生成的类创建一个构造方法，构造方法包含了所有的field；而不是使用setter；</div><div class="line">         --&gt;</div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"constructorBased"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 在targetPackage的基础上，根据数据库的schema再生成一层package，最终生成的类放在这个package下，默认为false --&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"enableSubPackages"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- for MyBatis3 / MyBatis3Simple</span></div><div class="line">            是否创建一个不可变的类，如果为true，</div><div class="line">            那么MBG会创建一个没有setter方法的类，取而代之的是类似constructorBased的类</div><div class="line">         --&gt;</div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"immutable"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 设置一个根对象，</span></div><div class="line">            如果设置了这个根对象，那么生成的keyClass或者recordClass会继承这个类；在Table的rootClass属性中可以覆盖该选项</div><div class="line">            注意：如果在key class或者record class中有root class相同的属性，MBG就不会重新生成这些属性了，包括：</div><div class="line">                1，属性名相同，类型相同，有相同的getter/setter方法；</div><div class="line">         --&gt;</div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"rootClass"</span> <span class="attr">value</span>=<span class="string">"com._520it.mybatis.domain.BaseDomain"</span>/&gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 设置是否在getter方法中，对String类型字段调用trim()方法 --&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"trimStrings"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">javaModelGenerator</span>&gt;</span></div><div class="line"></div><div class="line"></div><div class="line">    <span class="comment">&lt;!-- 生成SQL map的XML文件生成器，</span></div><div class="line">        注意，在Mybatis3之后，我们可以使用mapper.xml文件+Mapper接口（或者不用mapper接口），</div><div class="line">            或者只使用Mapper接口+Annotation，所以，如果 javaClientGenerator配置中配置了需要生成XML的话，这个元素就必须配置</div><div class="line">        targetPackage/targetProject:同javaModelGenerator</div><div class="line">     --&gt;</div><div class="line">    <span class="tag">&lt;<span class="name">sqlMapGenerator</span> <span class="attr">targetPackage</span>=<span class="string">"com._520it.mybatis.mapper"</span> <span class="attr">targetProject</span>=<span class="string">"src/main/resources"</span>&gt;</span></div><div class="line">        <span class="comment">&lt;!-- 在targetPackage的基础上，根据数据库的schema再生成一层package，最终生成的类放在这个package下，默认为false --&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"enableSubPackages"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">sqlMapGenerator</span>&gt;</span></div><div class="line"></div><div class="line"></div><div class="line">    <span class="comment">&lt;!-- 对于mybatis来说，即生成Mapper接口，注意，如果没有配置该元素，那么默认不会生成Mapper接口 </span></div><div class="line">        targetPackage/targetProject:同javaModelGenerator</div><div class="line">        type：选择怎么生成mapper接口（在MyBatis3/MyBatis3Simple下）：</div><div class="line">            1，ANNOTATEDMAPPER：会生成使用Mapper接口+Annotation的方式创建（SQL生成在annotation中），不会生成对应的XML；</div><div class="line">            2，MIXEDMAPPER：使用混合配置，会生成Mapper接口，并适当添加合适的Annotation，但是XML会生成在XML中；</div><div class="line">            3，XMLMAPPER：会生成Mapper接口，接口完全依赖XML；</div><div class="line">        注意，如果context是MyBatis3Simple：只支持ANNOTATEDMAPPER和XMLMAPPER</div><div class="line">    --&gt;</div><div class="line">    <span class="tag">&lt;<span class="name">javaClientGenerator</span> <span class="attr">targetPackage</span>=<span class="string">"com._520it.mybatis.mapper"</span> <span class="attr">type</span>=<span class="string">"ANNOTATEDMAPPER"</span> <span class="attr">targetProject</span>=<span class="string">"src/main/java"</span>&gt;</span></div><div class="line">        <span class="comment">&lt;!-- 在targetPackage的基础上，根据数据库的schema再生成一层package，最终生成的类放在这个package下，默认为false --&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"enableSubPackages"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 可以为所有生成的接口添加一个父接口，但是MBG只负责生成，不负责检查</span></div><div class="line">        &lt;property name="rootInterface" value=""/&gt;</div><div class="line">         --&gt;</div><div class="line">    <span class="tag">&lt;/<span class="name">javaClientGenerator</span>&gt;</span></div><div class="line"></div><div class="line">    <span class="comment">&lt;!-- 选择一个table来生成相关文件，可以有一个或多个table，必须要有table元素</span></div><div class="line">        选择的table会生成一下文件：</div><div class="line">        1，SQL map文件</div><div class="line">        2，生成一个主键类；</div><div class="line">        3，除了BLOB和主键的其他字段的类；</div><div class="line">        4，包含BLOB的类；</div><div class="line">        5，一个用户生成动态查询的条件类（selectByExample, deleteByExample），可选；</div><div class="line">        6，Mapper接口（可选）</div><div class="line"></div><div class="line">        tableName（必要）：要生成对象的表名；</div><div class="line">        注意：大小写敏感问题。正常情况下，MBG会自动的去识别数据库标识符的大小写敏感度，在一般情况下，MBG会</div><div class="line">            根据设置的schema，catalog或tablename去查询数据表，按照下面的流程：</div><div class="line">            1，如果schema，catalog或tablename中有空格，那么设置的是什么格式，就精确的使用指定的大小写格式去查询；</div><div class="line">            2，否则，如果数据库的标识符使用大写的，那么MBG自动把表名变成大写再查找；</div><div class="line">            3，否则，如果数据库的标识符使用小写的，那么MBG自动把表名变成小写再查找；</div><div class="line">            4，否则，使用指定的大小写格式查询；</div><div class="line">        另外的，如果在创建表的时候，使用的""把数据库对象规定大小写，就算数据库标识符是使用的大写，在这种情况下也会使用给定的大小写来创建表名；</div><div class="line">        这个时候，请设置delimitIdentifiers="true"即可保留大小写格式；</div><div class="line"></div><div class="line">        可选：</div><div class="line">        1，schema：数据库的schema；</div><div class="line">        2，catalog：数据库的catalog；</div><div class="line">        3，alias：为数据表设置的别名，如果设置了alias，那么生成的所有的SELECT SQL语句中，列名会变成：alias_actualColumnName</div><div class="line">        4，domainObjectName：生成的domain类的名字，如果不设置，直接使用表名作为domain类的名字；可以设置为somepck.domainName，那么会自动把domainName类再放到somepck包里面；</div><div class="line">        5，enableInsert（默认true）：指定是否生成insert语句；</div><div class="line">        6，enableSelectByPrimaryKey（默认true）：指定是否生成按照主键查询对象的语句（就是getById或get）；</div><div class="line">        7，enableSelectByExample（默认true）：MyBatis3Simple为false，指定是否生成动态查询语句；</div><div class="line">        8，enableUpdateByPrimaryKey（默认true）：指定是否生成按照主键修改对象的语句（即update)；</div><div class="line">        9，enableDeleteByPrimaryKey（默认true）：指定是否生成按照主键删除对象的语句（即delete）；</div><div class="line">        10，enableDeleteByExample（默认true）：MyBatis3Simple为false，指定是否生成动态删除语句；</div><div class="line">        11，enableCountByExample（默认true）：MyBatis3Simple为false，指定是否生成动态查询总条数语句（用于分页的总条数查询）；</div><div class="line">        12，enableUpdateByExample（默认true）：MyBatis3Simple为false，指定是否生成动态修改语句（只修改对象中不为空的属性）；</div><div class="line">        13，modelType：参考context元素的defaultModelType，相当于覆盖；</div><div class="line">        14，delimitIdentifiers：参考tableName的解释，注意，默认的delimitIdentifiers是双引号，如果类似MYSQL这样的数据库，使用的是`（反引号，那么还需要设置context的beginningDelimiter和endingDelimiter属性）</div><div class="line">        15，delimitAllColumns：设置是否所有生成的SQL中的列名都使用标识符引起来。默认为false，delimitIdentifiers参考context的属性</div><div class="line"></div><div class="line">        注意，table里面很多参数都是对javaModelGenerator，context等元素的默认属性的一个复写；</div><div class="line">     --&gt;</div><div class="line">    <span class="tag">&lt;<span class="name">table</span> <span class="attr">tableName</span>=<span class="string">"userinfo"</span> &gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 参考 javaModelGenerator 的 constructorBased属性--&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"constructorBased"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 默认为false，如果设置为true，在生成的SQL中，table名字不会加上catalog或schema； --&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"ignoreQualifiersAtRuntime"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 参考 javaModelGenerator 的 immutable 属性 --&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"immutable"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 指定是否只生成domain类，如果设置为true，只生成domain类，如果还配置了sqlMapGenerator，那么在mapper XML文件中，只生成resultMap元素 --&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"modelOnly"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 参考 javaModelGenerator 的 rootClass 属性 </span></div><div class="line">        &lt;property name="rootClass" value=""/&gt;</div><div class="line">         --&gt;</div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 参考javaClientGenerator 的  rootInterface 属性</span></div><div class="line">        &lt;property name="rootInterface" value=""/&gt;</div><div class="line">        --&gt;</div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 如果设置了runtimeCatalog，那么在生成的SQL中，使用该指定的catalog，而不是table元素上的catalog </span></div><div class="line">        &lt;property name="runtimeCatalog" value=""/&gt;</div><div class="line">        --&gt;</div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 如果设置了runtimeSchema，那么在生成的SQL中，使用该指定的schema，而不是table元素上的schema </span></div><div class="line">        &lt;property name="runtimeSchema" value=""/&gt;</div><div class="line">        --&gt;</div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 如果设置了runtimeTableName，那么在生成的SQL中，使用该指定的tablename，而不是table元素上的tablename </span></div><div class="line">        &lt;property name="runtimeTableName" value=""/&gt;</div><div class="line">        --&gt;</div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 注意，该属性只针对MyBatis3Simple有用；</span></div><div class="line">            如果选择的runtime是MyBatis3Simple，那么会生成一个SelectAll方法，如果指定了selectAllOrderByClause，那么会在该SQL中添加指定的这个order条件；</div><div class="line">         --&gt;</div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"selectAllOrderByClause"</span> <span class="attr">value</span>=<span class="string">"age desc,username asc"</span>/&gt;</span></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- 如果设置为true，生成的model类会直接使用column本身的名字，而不会再使用驼峰命名方法，比如BORN_DATE，生成的属性名字就是BORN_DATE,而不会是bornDate --&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"useActualColumnNames"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></div><div class="line"></div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- generatedKey用于生成生成主键的方法，</span></div><div class="line">            如果设置了该元素，MBG会在生成的&lt;insert&gt;元素中生成一条正确的&lt;selectKey&gt;元素，该元素可选</div><div class="line">            column:主键的列名；</div><div class="line">            sqlStatement：要生成的selectKey语句，有以下可选项：</div><div class="line">                Cloudscape:相当于selectKey的SQL为： VALUES IDENTITY_VAL_LOCAL()</div><div class="line">                DB2       :相当于selectKey的SQL为： VALUES IDENTITY_VAL_LOCAL()</div><div class="line">                DB2_MF    :相当于selectKey的SQL为：SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1</div><div class="line">                Derby      :相当于selectKey的SQL为：VALUES IDENTITY_VAL_LOCAL()</div><div class="line">                HSQLDB      :相当于selectKey的SQL为：CALL IDENTITY()</div><div class="line">                Informix  :相当于selectKey的SQL为：select dbinfo('sqlca.sqlerrd1') from systables where tabid=1</div><div class="line">                MySql      :相当于selectKey的SQL为：SELECT LAST_INSERT_ID()</div><div class="line">                SqlServer :相当于selectKey的SQL为：SELECT SCOPE_IDENTITY()</div><div class="line">                SYBASE      :相当于selectKey的SQL为：SELECT @@IDENTITY</div><div class="line">                JDBC      :相当于在生成的insert元素上添加useGeneratedKeys="true"和keyProperty属性</div><div class="line">        &lt;generatedKey column="" sqlStatement=""/&gt;</div><div class="line">         --&gt;</div><div class="line"></div><div class="line">        <span class="comment">&lt;!-- </span></div><div class="line">            该元素会在根据表中列名计算对象属性名之前先重命名列名，非常适合用于表中的列都有公用的前缀字符串的时候，</div><div class="line">            比如列名为：CUST_ID,CUST_NAME,CUST_EMAIL,CUST_ADDRESS等；</div><div class="line">            那么就可以设置searchString为"^CUST_"，并使用空白替换，那么生成的Customer对象中的属性名称就不是</div><div class="line">            custId,custName等，而是先被替换为ID,NAME,EMAIL,然后变成属性：id，name，email；</div><div class="line"></div><div class="line">            注意，MBG是使用java.util.regex.Matcher.replaceAll来替换searchString和replaceString的，</div><div class="line">            如果使用了columnOverride元素，该属性无效；</div><div class="line"></div><div class="line">        &lt;columnRenamingRule searchString="" replaceString=""/&gt;</div><div class="line">         --&gt;</div><div class="line"></div><div class="line"></div><div class="line">         <span class="comment">&lt;!-- 用来修改表中某个列的属性，MBG会使用修改后的列来生成domain的属性；</span></div><div class="line">             column:要重新设置的列名；</div><div class="line">             注意，一个table元素中可以有多个columnOverride元素哈~</div><div class="line">          --&gt;</div><div class="line">         <span class="tag">&lt;<span class="name">columnOverride</span> <span class="attr">column</span>=<span class="string">"username"</span>&gt;</span></div><div class="line">             <span class="comment">&lt;!-- 使用property属性来指定列要生成的属性名称 --&gt;</span></div><div class="line">             <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"property"</span> <span class="attr">value</span>=<span class="string">"userName"</span>/&gt;</span></div><div class="line"></div><div class="line">             <span class="comment">&lt;!-- javaType用于指定生成的domain的属性类型，使用类型的全限定名</span></div><div class="line">             &lt;property name="javaType" value=""/&gt;</div><div class="line">              --&gt;</div><div class="line"></div><div class="line">             <span class="comment">&lt;!-- jdbcType用于指定该列的JDBC类型 </span></div><div class="line">             &lt;property name="jdbcType" value=""/&gt;</div><div class="line">              --&gt;</div><div class="line"></div><div class="line">             <span class="comment">&lt;!-- typeHandler 用于指定该列使用到的TypeHandler，如果要指定，配置类型处理器的全限定名</span></div><div class="line">                 注意，mybatis中，不会生成到mybatis-config.xml中的typeHandler</div><div class="line">                 只会生成类似：where id = #<span class="template-variable">&#123;id,jdbcType=BIGINT,typeHandler=com._520it.mybatis.MyTypeHandler&#125;</span><span class="xml"><span class="comment">的参数描述</span></span></div><div class="line">             &lt;property name="jdbcType" value=""/&gt;</div><div class="line">             --&gt;</div><div class="line"></div><div class="line">             <span class="comment">&lt;!-- 参考table元素的delimitAllColumns配置，默认为false</span></div><div class="line">             &lt;property name="delimitedColumnName" value=""/&gt;</div><div class="line">              --&gt;</div><div class="line">         <span class="tag">&lt;/<span class="name">columnOverride</span>&gt;</span></div><div class="line"></div><div class="line">         <span class="comment">&lt;!-- ignoreColumn设置一个MGB忽略的列，如果设置了改列，那么在生成的domain中，生成的SQL中，都不会有该列出现 </span></div><div class="line">             column:指定要忽略的列的名字；</div><div class="line">             delimitedColumnName：参考table元素的delimitAllColumns配置，默认为false</div><div class="line"></div><div class="line">             注意，一个table元素中可以有多个ignoreColumn元素</div><div class="line">         &lt;ignoreColumn column="deptId" delimitedColumnName=""/&gt;</div><div class="line">         --&gt;</div><div class="line">    <span class="tag">&lt;/<span class="name">table</span>&gt;</span></div><div class="line"></div><div class="line"><span class="tag">&lt;/<span class="name">context</span>&gt;</span></div><div class="line"></div><div class="line"><span class="tag">&lt;/<span class="name">generatorConfiguration</span>&gt;</span></div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/学习笔记/" rel="tag"># 学习笔记</a>
          
            <a href="/tags/java/" rel="tag"># java</a>
          
            <a href="/tags/mybatis/" rel="tag"># mybatis</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/03/08/Eclipse如何修改dynamic-web-module-version/" rel="next" title="Eclipse如何修改dynamic web module version">
                <i class="fa fa-chevron-left"></i> Eclipse如何修改dynamic web module version
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/03/10/SSM框架搭建学习笔记/" rel="prev" title="SSM框架搭建学习笔记">
                SSM框架搭建学习笔记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/uploads/touxiang.jpeg"
               alt="我爱的乌托邦" />
          <p class="site-author-name" itemprop="name">我爱的乌托邦</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#MyBatis-Generator"><span class="nav-number">2.</span> <span class="nav-text">MyBatis Generator</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#使用maven插件"><span class="nav-number">2.1.</span> <span class="nav-text">使用maven插件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#配置pom-xml"><span class="nav-number">2.1.1.</span> <span class="nav-text">配置pom.xml</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置generatorConfig-xml"><span class="nav-number">2.1.2.</span> <span class="nav-text">配置generatorConfig.xml</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#执行maven命令"><span class="nav-number">2.1.3.</span> <span class="nav-text">执行maven命令</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用mybatis-generator的jar包直接生成"><span class="nav-number">2.2.</span> <span class="nav-text">使用mybatis-generator的jar包直接生成</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#把mybatis-generator-core-1-3-2-jar和generatorConfig-xml放在同一目录下"><span class="nav-number">2.2.1.</span> <span class="nav-text">把mybatis-generator-core-1.3.2.jar和generatorConfig.xml放在同一目录下</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#执行命令"><span class="nav-number">2.2.2.</span> <span class="nav-text">执行命令</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#参考文件"><span class="nav-number">3.</span> <span class="nav-text">参考文件</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">我爱的乌托邦</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    
    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  





  



  
  

  

  

  

  


  

</body>
</html>
